#include "gameinit.h"

void initGame(){
	extern Game game;
	disable();
		
	game.hero.lives = 3;
	game.hero.score = 0;
	game.hero.blinking = false;
	game.hero.blinktime = RECOVERY_TIME;
	

	game.hero.stone.exist = false;

	game.liveSprite->x = HRES - game.liveSprite->width - 5;
	game.liveSprite->y = 10;
	
	enable();
}

void L1init(){
	extern Game game;
	extern ConfigInfo conf;
	disable();
	//display loading

	game.loadingText->x=30;
	game.loadingText->y=250;
	draw_sprite(game.loadingText,game.loading->map);
	memcpy(conf.video_base,game.loading->map,HRES*VRES);
	
	
	game.hero.sprite->x = 5;
	game.hero.sprite->y = 400;
	game.hero.sprite->xspeed = 0;
	game.hero.sprite->yspeed = 0;
	game.hero.jump = 0;
	game.hero.jumpBegin = 0;
	game.hero.shooting = 0;
	game.hero.dx = 0;
	game.hero.vSpeed = 0;
	game.hero.temp_y = game.hero.sprite->y;

	//drawStringAt("Highscores", 0, 300, 16, 0, 2, conf.video_base, conf.table);
	
	game.level1.enemy.alive = true;
	game.level1.enemy.sprite->x = 600;
	game.level1.enemy.sprite->y = 490;
	game.level1.enemy.dumbl = DUMBNESS_L1;
	game.level1.enemy.dumbr = DUMBNESS_L1;
	game.level1.enemy.isMonster = false;
	game.level1.enemy.direction = 1;
	
	//drawStringAt("Highscores2", 0, 400, 16, 0, 2, conf.video_base, conf.table);
	
	game.level1.intro.bg->x = 0;
	game.level1.intro.bg->y = 0;
	game.level1.intro.logo->x = 0;
	game.level1.intro.logo->y = 0;
	game.level1.intro.sequel->x = 0;
	game.level1.intro.sequel->y = 0;
	game.level1.intro.title->x = 240;
	game.level1.intro.title->y = 290;
	game.level1.intro.text->x = 80;
	game.level1.intro.text->y = 330;
	game.level1.intro.mouse1->x = 0;
	game.level1.intro.mouse1->y = 0;
	game.level1.intro.mouse2->x = 0;
	game.level1.intro.mouse2->y = 0;
	
	game.level1.finish.x = 0;
	game.level1.finish.y = 0;
	game.level1.finish.width = 50;
	game.level1.finish.height = 200;
	game.level1.songNumber = 1;	
	//drawStringAt("Highscores3", 0, 500, 16, 0, 2, conf.video_base, conf.table);
	enable();
}

void L2init(){
	extern Game game;
	extern ConfigInfo conf;
	disable();
	//display loading
	memcpy(conf.video_base,game.loading->map,HRES*VRES);
	
	destroy_sprite(game.hero.sprite);
	
	game.hero.sprite = create_sprite(mm2_xpm);
	game.hero.sprite->x = 700;
	game.hero.sprite->y = 0;
	game.hero.sprite->xspeed = 0;
	game.hero.sprite->yspeed = 0;
	
	if(map(conf.secActual,0,100,500,0)>0)
		game.hero.score += map(conf.secActual,0,100,500,0);
		
	game.hero.jump = 0;
	game.hero.jumpBegin = 0;
	game.hero.shooting = 0;
	game.hero.dx = 0;
	game.hero.vSpeed = 0;
	game.hero.temp_y = game.hero.sprite->y;

	
	
	
	game.level2.enemy.alive = true;
	game.level2.enemy.sprite->x = 600;
	game.level2.enemy.sprite->y = 490;
	game.level2.enemy.dumbl = DUMBNESS_L2;
	game.level2.enemy.dumbr = DUMBNESS_L2;
	game.level2.enemy.isMonster = false;
	game.level2.enemy.direction = 1;
	
	
	game.level2.intro.bg->x = 0;
	game.level2.intro.bg->y = 0;
	game.level2.intro.logo->x = 0;
	game.level2.intro.logo->y = 0;
	game.level2.intro.sequel->x = 0;
	game.level2.intro.sequel->y = 0;
	game.level2.intro.title->x = 240;
	game.level2.intro.title->y = 290;
	game.level2.intro.text->x = 80;
	game.level2.intro.text->y = 330;
	game.level2.intro.mouse1->x = 0;
	game.level2.intro.mouse1->y = 0;
	game.level2.intro.mouse2->x = 0;
	game.level2.intro.mouse2->y = 0;
	
	game.level2.finish.x = 750;
	game.level2.finish.y = 200;
	game.level2.finish.width = 50;
	game.level2.finish.height = 100;
	game.level2.songNumber = 2;
	
	enable();
}

void L3init(){
	extern Game game;
	extern ConfigInfo conf;
	disable();
	//display loading
	memcpy(conf.video_base,game.loading->map,HRES*VRES);
	
	destroy_sprite(game.hero.sprite);
	
	game.hero.sprite = create_sprite(mm3_xpm);
	
	game.hero.sprite->x = 700;
	game.hero.sprite->y = 0;
	game.hero.sprite->xspeed = 0;
	game.hero.sprite->yspeed = 0;
	
	if(map(conf.secActual,0,200,500,0)>0)
		game.hero.score += map(conf.secActual,0,200,500,0);
		
	game.hero.jump = 0;
	game.hero.jumpBegin = 0;
	game.hero.shooting = 0;
	game.hero.dx = 0;
	game.hero.vSpeed = 0;
	game.hero.temp_y = game.hero.sprite->y;

		
	game.level3.enemy.alive = true;
	game.level3.enemy.sprite->x = 400;
	game.level3.enemy.sprite->y = 270;
	game.level3.enemy.dumbl = DUMBNESS_L2;
	game.level3.enemy.dumbr = DUMBNESS_L2;
	game.level3.enemy.isMonster = true;
	game.level3.enemy.lives=10;
	game.level3.enemy.direction = -1;
	
	
	
	game.level3.intro.bg->x = 0;
	game.level3.intro.bg->y = 0;
	game.level3.intro.logo->x = 0;
	game.level3.intro.logo->y = 0;
	game.level3.intro.sequel->x = 0;
	game.level3.intro.sequel->y = 0;
	game.level3.intro.title->x = 240;
	game.level3.intro.title->y = 290;
	game.level3.intro.text->x = 80;
	game.level3.intro.text->y = 330;
	game.level3.intro.mouse1->x = 0;
	game.level3.intro.mouse1->y = 0;
	game.level3.intro.mouse2->x = 0;
	game.level3.intro.mouse2->y = 0;
	
	
	game.level3.finish.x = 0;
	game.level3.finish.y = 0;
	game.level3.finish.width = 50;
	game.level3.finish.height = 200;
	game.level3.songNumber = 3;
	
	enable();
}

void LIntro(Level * level){
	extern char* double_buffer;
	extern Queue keys_queue;
	extern int last_sc;
	extern ConfigInfo conf;
	//drawStringAt("lalalala", 0, 500, 16, 0, 2, conf.video_base, conf.table);
	char bg[HRES*VRES];
	draw_sprite(level->intro.bg,bg);
	if(level->songNumber==1){
		//drawStringAt("Hfjfkjhf", 0, 400, 16, 0, 2, conf.video_base, conf.table);
		while(level->intro.logo->x < 80 || level->intro.logo->y < 180){
			memcpy(double_buffer,bg,HRES*VRES);
			draw_sprite(level->intro.logo,double_buffer);
			if(level->intro.logo->x < 80) level->intro.logo->x+= 1;
			if(level->intro.logo->y < 180) level->intro.logo->y+= 1;
			memcpy(conf.video_base,double_buffer,HRES*VRES);
		}
		
		draw_sprite(level->intro.bg,bg);
		draw_sprite(level->intro.logo,bg);
		while(level->intro.sequel->x < 80 || level->intro.sequel->y < 240//){
		|| level->intro.mouse1->x < 650 || level->intro.mouse1->y < 100){
			memcpy(double_buffer,bg,HRES*VRES);
			draw_sprite(level->intro.sequel,double_buffer);	
			draw_sprite(level->intro.mouse1,double_buffer);
			if(level->intro.sequel->x < 80) level->intro.sequel->x += 1;
			if(level->intro.sequel->y < 240) level->intro.sequel->y += 1;
			if(level->intro.mouse1->x < 650) level->intro.mouse1->x += 10;
			if(level->intro.mouse1->y < 100) level->intro.mouse1->y += 1;
			memcpy(conf.video_base,double_buffer,HRES*VRES);
		}
	}
	level->intro.logo->x = 80;
	level->intro.logo->y = 180;
	level->intro.sequel->x = 80;
	level->intro.sequel->y = 240;
	level->intro.mouse1->x = 650;
	level->intro.mouse1->y = 100;
	
	//DISPLAY TITLE
	draw_sprite(level->intro.bg,bg);
	draw_sprite(level->intro.logo,bg);
	draw_sprite(level->intro.sequel,bg);
	draw_sprite(level->intro.mouse1,bg);
	draw_sprite(level->intro.title,bg);	
	memcpy(conf.video_base,bg,HRES*VRES);
	
	//DISPLAY MOUSE
	
	//DISPLAY TEXT
	draw_sprite(level->intro.bg,bg);
	draw_sprite(level->intro.logo,bg);
	draw_sprite(level->intro.sequel,bg);
	draw_sprite(level->intro.mouse1,bg);
	draw_sprite(level->intro.title,bg);
	draw_sprite(level->intro.text,bg);	
	memcpy(conf.video_base,bg,HRES*VRES);
	
	queueClear(&keys_queue);
	do{
		if(!queueEmpty(&keys_queue))
		{
			last_sc = queueGet(&keys_queue);
		}
	}
	while(last_sc!=KEY_ENTER);
	
	int sec;
	conf.secBegin=get_time(&sec, &(conf.minBegin), &(conf.hourBegin));
}
